// 交叉跨越点管理
import { filter } from "lodash";
import request from "./axios";

export const CrossingPointAPI = {
  //  获取跨越点列表

  getList: (params) => request.get("/entities/CrossingPoint", { params }),

  //  获取单个跨越点详情
  getDetail: (id) => request.get(`/entities/CrossingPoint/${id}`),

  //  * 新增跨越点

  create: (data) => request.post("/entities/CrossingPoint", data),

  //  更新跨越点

  update: (id, data) => request.put(`/entities/CrossingPoint/${id}`, data),

  //  删除跨越点

  delete: (id) => request.delete(`/entities/CrossingPoint/${id}`),

  // 导入 （批量创建）
  bulkCreate: (data) => request.post("/entities/CrossingPoint/bulk", data),

  filter: (id) => request.get(`/entities/CrossingPoint?ProjectId=${id}`),

  getCrossingPoint: (id) =>
    request.get(`/entities/CrossingPoint?projectId=${id}`),

  recommend: (id) => request.get(`/entities/CrossingPoint/recommend/${id}`),

  // 下载模版
  importTemplate: () =>
    request.get(`/entities/CrossingPoint/importTemplate`, {
      responseType: "blob", // 表明返回服务器返回的数据类型
    }),

  //上传
  import: (file) => {
    const formData = new FormData();
    formData.append("file", file); // 假设后端接收文件的参数名为file
    return request.post(`/entities/CrossingPoint/import`, formData, {
      headers: {
        "Content-Type": "multipart/form-data", // 上传文件需指定该Content-Type
      },
    });
  },

  // 导入 （批量创建）
  importData: (projectId, data) =>
    request.post(`/entities/CrossingPoint/importData/${projectId}`, data),
};
